import { createRouter, createWebHashHistory } from 'vue-router'
// vue3.x中createRouter来创建路由实例，createWebHashHistory代表使用hash模式的路由
import Login from '@/views/Login'
import Layout from '@/views/Layout'
import Category from '@/views/Category'
import Home from '@/views/Home/index'
import Good from '@/views/goods/index'
import Cart from '@/views/Cart/index'
import settle from '@/views/settle/index'
import pay from '@/views/Pay/index'
import payBack from '@/views/Pay/callback.vue'

const routes = [// 创建路由实例
  {
    path: '/login',
    component: Login
  },

  {
    path: '/',
    component: Layout,
    children: [{
      path: 'category/:id',
      component: Category
    },
    {
      path: 'goods/:id',
      component: Good
    },
    {
      path: 'cart',
      component: Cart
    },
    {
      path: 'settle',
      component: settle
    },
    {
      path: 'pay',
      component: pay
    },
    {
      path: 'pay/callback',
      component: payBack
    },
    {
      path: '',
      component: Home
    }]
  }

]

const router = createRouter({ // 使用hash方式实现路由
  history: createWebHashHistory(),
  routes // 配置路由规则，写法和之前一样
})

export default router
